﻿#include "Widget.h"
#include "JPieChart.h"
#include "JBarChart.h"

#include <QPushButton>
#include <QBoxLayout>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    this->resize(400, 200);

    QPushButton *pShowPieChartBtn = new QPushButton(QStringLiteral("显示饼图"), this);
    connect(pShowPieChartBtn, &QPushButton::clicked, this, &Widget::showPieChart);

    QPushButton *pShowBarChartBtn = new QPushButton(QStringLiteral("显示柱状图"), this);
    connect(pShowBarChartBtn, &QPushButton::clicked, this, &Widget::showBarChart);

    QVBoxLayout *pLayout = new QVBoxLayout(this);
    pLayout->addWidget(pShowPieChartBtn);
    pLayout->addWidget(pShowBarChartBtn);
}

Widget::~Widget()
{

}

void Widget::showPieChart()
{
    JPieChart *pPieChart = new JPieChart(NULL);
    pPieChart->resize(1000, 750);

    QList<double> valueList;
    valueList << 90 << 65 << 110 << 40 << 55 << 30;
    pPieChart->setAnimation(true);
    //pPieChart->setInnerCircleVisible(false);
    pPieChart->setValue(valueList);

    pPieChart->show();
}

void Widget::showBarChart()
{
    JBarChart *pBarChart = new JBarChart(NULL);
    pBarChart->resize(1000, 750);

    QList<double> valueList;
    valueList << 90 << 65 << 110 << 40 << 55 << 30 << 120;
    QStringList textList;
    textList << QStringLiteral("一月") << QStringLiteral("二月") << QStringLiteral("三月")
             << QStringLiteral("四月") << QStringLiteral("五月") << QStringLiteral("六月")
             << QStringLiteral("七月");
    pBarChart->setAnimation(true);
    pBarChart->setTextColor(QColor(248, 203, 127));
    pBarChart->setBarColor(Qt::green);
    pBarChart->setGridColor(QColor(118, 218, 145));
    pBarChart->setMultiColor(true);
    pBarChart->setValue(valueList, textList);

    pBarChart->show();
}

